<?php
function view_producnt_list($product_list)
{
	$list = "<table class='product_list'>\n";

	foreach ($product_list as $product)
	{
		$list = $list . view_product($product["small_image"], $product["name"], $product["model"], $product["specification"] , $product["market_price"] , $product["promotional_price"] , $product["click_count"] , $product["detail_view_url"]);
	}
	$list = $list . "</table>\n";

	return $list;
}

function view_product($picture, $name, $model, $specification, $market_price, $promotional_price, $click_count, $detail_view_url)
{
	$product = sprintf(
	"<table class='product_intro'>
		<tr> <td class='product_picture' rowspan='8'><a href='%s'><img src='%s'></a></td></tr>
		<tr> <td class='product_name'><a href='%s'>%s</a> </td></tr>
		<tr> <td class='product_model'>型号:%s</td> </tr>
		<tr> <td class='product_specification'>规格:%s</td> </tr>
		<tr> <td class='product_market_prcie'>市场价:%f</td> </tr>
		<tr> <td class='product_promotional_price'>优惠价:%f</td> </tr>
		<tr> <td class='product_click_count'>点击数:%d</td> </tr>
		<tr> <td class='product_edit'><a href='%s'>获得详情</a></td> </tr>
	</table>",
		$detail_view_url, '../upload/' . $picture,
		$detail_view_url, $name,
		$model,
		$specification,
		$market_price,
		$promotional_price,
		$click_count,
		$detail_view_url
	);

	return $product;
}

function view_product_list_index_page($product_list)
{
	$list = "<table class='product_list'>\n";

	foreach ($product_list as $product)
	{
		$list = $list . view_product_index_page($product["small_image"], $product["name"], $product["model"], $product["specification"] , $product["market_price"] , $product["promotional_price"] , $product["click_count"] , $product["detail_view_url"]);
	}
	$list = $list . "</table>\n";

	return $list;
}

function view_product_index_page($picture, $name, $model, $specification, $market_price, $promotional_price, $click_count, $detail_view_url)
{
	$product = sprintf(
	"<table class='product_intro'>
		<tr> <td class='product_picture'><a href='%s'><img src='%s'></a></td></tr>
		<tr> <td class='product_name'><a href='%s'>%s</a> </td></tr>
	</table>",
		"/product/list.php", '../upload/' . $picture,
		"/product/list.php", $name
	);

	return $product;
}

function view_page_list($page, $page_count, $type)
{
	$page_list = "";

	// 如果需要，显示上一页
	if ($page > 1)
	{
		if ($type)
		{
			$page_list = $page_list . sprintf("<a href=\"product_list.php?page=%d&type=%d\">上一页</a>", $page - 1, $type);
		}
		else
		{
			$page_list = $page_list . sprintf("<a href=\"product_list.php?page=%d\">上一页</a>", $page - 1);
		}
	}
	// 如果需要，显示下一页
	if ($page + 1 < $page_count)
	{
		if ($type)
		{
			$page_list = $page_list . sprintf("<a href=\"product_list.php?page=%d&type=%d\">下一页</a>", $page + 1, $type);
		}
		else
		{
			$page_list = $page_list . sprintf("<a href=\"product_list.php?page=%d\">下一页</a>", $page + 1);
		}
	}
	$page_list = $page_list . sprintf("%d/%d", $page, $page_count);

	return $page_list;
}

function view_product_detail($picture, $name, $model, $specification, $market_price, $promotional_price, $intro, $details, $publish_time, $click_count)
{
	$product_detail = sprintf(
		"<!--product start-->
		<div class='product'>
		 <div class='product_picture'><img src='%s'></div>
		 <div class='product_name'>%s</div>
		 <div class='product_model'>型号:%s</div>
		 <div class='product_specification'>规格:%s</div>
		 <div class='product_market_prcie'>市场价:%f</div>
		 <div class='product_promotional_price'>优惠价:%f</div>
		 <div class='product_publish_time'>发布时间:%s</div>
		 <div class='product_intro'>产品简介:%s</div>
		 <div class='product_details'>详细介绍:%s</div>
		 <div class='product_click_count'>点击数:%d</div>
		 <div class='product_print'>打印此页</div>
		</div>
		<!--product end-->",
		'../upload/' . $picture,
		$name,
		$model,
		$specification,
		$market_price,
		$promotional_price,
		$publish_time,
		$intro,
		$details,
		$click_count
	);
	return $product_detail;	
}

?>
